home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog Special Freeware 31
/
FreelogHS31.iso
/
ArgentCompta
/
FASTCAISSE
/
Setup FASTCAISSE.exe
/
{app}
/
A faire70.sql
< prev
next >
Wrap
Text File
|
2005-06-01
|
4KB
|
168 lines
/* SUPPRIMER LES DEPENDANCES ENVERS LIGNES.PRIX */
DROP VIEW "LIGNES1";
DROP VIEW "LIGNES2";
DROP PROCEDURE "UPDATE_REMISE_CLIENTS";
COMMIT;
DROP PROCEDURE "GET_REMISE_CLIENTS";
COMMIT;
DROP PROCEDURE "GET_CA_CLIENT";
COMMIT;
ALTER TABLE LIGNES ALTER COLUMN PRIX TYPE DECIMAL(14,6);
ALTER TABLE LIGNEMACRO ALTER COLUMN PRIX TYPE DECIMAL(14,6);
COMMIT;
CREATE VIEW "LIGNES1" (
"DATEPIECE",
"INDEXPIECE",
"NOLIGNE",
"INDEXARTICLE",
"QUANTITE",
"RAYON",
"TOTALTTC"
) AS
select CAST(DATEPIECE AS DATE),
l.INDEXPIECE,l.NOLIGNE,l.INDEXARTICLE,L.QUANTITE,
A.RAYON*10000+A.FAMILLE*100+A.SSFAMILLE,
CAST(l.PRIX*l.QUANTITE*(10000+TVA-((REMISE+PCREDUC+PCESCOMPTE)*100))/10000 AS DECIMAL(12,2))
from pieces P
JOIN LIGNES L ON L.INDEXPIECE=P.INDX
JOIN ARTICLES A ON A.INDX=L.INDEXARTICLE
WHERE Z=1 AND (PRIX*QUANTITE)<>0
;
/* View: LIGNES2, Owner: SYSDBA */
CREATE VIEW "LIGNES2" (
"DATEPIECE",
"INDEXPIECE",
"NOLIGNE",
"INDEXARTICLE",
"QTE",
"PKEYRAYON",
"TOTALTTC",
"DPAUHT",
"PMPA",
"MOIS",
"ANNEE"
) AS
select CAST(DATEPIECE AS DATE),
l.INDEXPIECE,l.NOLIGNE,l.INDEXARTICLE,QUANTITE,
A.RAYON*10000+A.FAMILLE*100+A.SSFAMILLE,
CAST(l.PRIX*l.QUANTITE*(10000+TVA-((REMISE+PCREDUC+PCESCOMPTE)*100))/10000 AS DECIMAL(12,2)),
A.DPAUHT,A.PMPA,
CAST(SUBSTR(DATEPIECE,6,7) AS SMALLINT),
CAST(SUBSTR(DATEPIECE,1,4) AS SMALLINT)
from pieces P
JOIN LIGNES L ON L.INDEXPIECE=P.INDX AND (PRIX*QUANTITE)<>0
JOIN ARTICLES A ON A.INDX=L.INDEXARTICLE
WHERE Z=1
;
COMMIT;
CREATE PROCEDURE "GET_CA_CLIENT"
(
"INDEX_CLIENT" INTEGER,
"DATEDEB" DATE,
"DATEFIN" DATE
)
RETURNS
(
"CA" DECIMAL(14, 2),
"CA_TOTAL" DECIMAL(14, 2)
)
AS
DECLARE VARIABLE CA1 DECIMAL(14,2);
DECLARE VARIABLE CA2 DECIMAL(14,2);
BEGIN
select SUM(TOTALTTC) FROM PIECES WHERE NOTIERS=:INDEX_CLIENT
AND Z=1
AND DATEPIECE>=:DATEDEB
AND DATEPIECE<=:DATEFIN
INTO :CA_TOTAL;
IF ((NOT CA_TOTAL IS NULL) AND (CA_TOTAL<>0)) then
BEGIN
/* CALCUL DES LIGNES HORS-CA */
SELECT SUM(CAST(L.PRIX*L.QUANTITE*(10000+L.TVA-(L.REMISE*100))/10000 AS DECIMAL(12,2))) from lignes L
join pieces p on p.indx=l.indexpiece
AND P.NOTIERS=:INDEX_CLIENT
AND P.Z=1
AND P.DATEPIECE>=:DATEDEB
AND P.DATEPIECE<=:DATEFIN
JOIN ARTICLES A ON A.INDX=L.INDEXARTICLE
JOIN RAYONS R ON R.PKEY=A.PKEYR
WHERE R.HORS_CA=1 OR A.HORS_CA=1
INTO :CA1;
IF (CA1 IS NULL) THEN CA = :CA_TOTAL; ELSE CA = :CA_TOTAL - :CA1;
END
ELSE
BEGIN
CA = 0;
CA_TOTAL = 0;
END
SUSPEND;
END
;
COMMIT;
CREATE PROCEDURE "GET_REMISE_CLIENTS"
(
"DATEDEB" DATE,
"DATEFIN" DATE
)
RETURNS
(
"INDEX_CLIENT" INTEGER,
"CA" DECIMAL(14, 2),
"REMISE" DECIMAL(5, 2),
"CA_TOTAL" DECIMAL(14, 2)
)
AS
BEGIN
FOR SELECT INDX FROM CLIENTS INTO :INDEX_CLIENT DO
BEGIN
SELECT "CA","CA_TOTAL" FROM GET_CA_CLIENT(:INDEX_CLIENT,:DATEDEB,:DATEFIN) INTO CA,CA_TOTAL;
IF (CA IS NULL) THEN
BEGIN
REMISE=0;
CA = 0;
END
ELSE SELECT "REMISE" FROM CALCUL_REMISE(:CA) INTO :REMISE;
SUSPEND;
END
END
;
COMMIT;
CREATE PROCEDURE "UPDATE_REMISE_CLIENTS"
(
"DATEDEB" DATE,
"DATEFIN" DATE
)
AS
DECLARE VARIABLE "INDEX_CLIENT" INTEGER;
DECLARE VARIABLE "CA" DECIMAL(14, 2);
DECLARE VARIABLE "REMISE" DECIMAL(5, 2);
BEGIN
FOR SELECT INDX FROM CLIENTS INTO :INDEX_CLIENT DO
BEGIN
SELECT "CA" FROM GET_CA_CLIENT(:INDEX_CLIENT,:DATEDEB,:DATEFIN) INTO :CA;
IF (CA IS NULL) THEN REMISE=0;
ELSE SELECT "REMISE" FROM CALCUL_REMISE(:CA) INTO :REMISE;
UPDATE CLIENTS SET "REMISE"=:REMISE WHERE "INDX"=:INDEX_CLIENT;
END
END
;
COMMIT;
SET GENERATOR VERSION_BASE TO 70;